const postData = require('../../data/post-data.js');
const app = getApp();
// pages/posts/posts.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    posts: [],
    image:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var _this = this;
    app.getAccessToken().then(function(){
      _this.getImdexBammerData(3);
    });
    var data = getApp();
    _this.setData({
      posts: data.globalData || []
    })
  },
  getImdexBammerData:function(num){
    var _token = wx.getStorageSync('token');
    var _this = this;
    wx.request({
      url: `${app.globalData.myApiBaseUrl}/banner/index/number/${num}`,
     method:'POST',
     header: {
       'content-type': 'application/x-www-form-urlencoded', // 默认值
       'token': _token
     },
     success (res) {
       if(res.data.code == 1) {
          _this.setData({
            image: res.data.data
          })
       } else {
        wx.showToast({
          title:res.data.msg,
          icon:'fail',
          duration:2000
        })
       }
     }
    })
  },

  onPostTap: function(e) {
    const postId = e.currentTarget.dataset.postId;
    wx.navigateTo({
      url: `post-detail/post-detail?id=${postId}`
    })
  },

  onSwiperTap: function(e) {
    const postId = e.target.dataset.postId;
    wx.navigateTo({
      url: `post-detail/post-detail?id=${postId}`
    })
  }
})